const axios = require('axios');

const cheerio = require('cheerio')

const url = 'http://www.xbmu.edu.cn/frontChannelPage.action?siteId=18articleClassId=104'
axios.get(url)
    .then(function (response) {
        // handle success
        console.log(response);

        if ((m = reges.exec(const $ = ((response.data));
        )) !== null) {

    console.log(m[1]);
}
    })
//使用cheerio分析信息
const $ = cheerio.load(response.data);
//使用CSS选择符选择内容

console.log($('title').text()) ；
//console.log($('#container div.list-right > div-list-right-main > ul >').text());
//$('#container div.list-right > div-list-right-main > ul >').each(){
//const newDate = $(element).replaceWith().text();
//const item = $(element).text();
//const link = $(element).attr('href');
//console.log(newDate, item, link);
//};
$('#container div.list-right > div-list-right-main > ul >').each(){
    const newDate = $(element).replaceWith().text();
    const item = $(element).text();
    const link = $(element).attr('href');
    console.log(newDate, item, link);
};
    .catch (function (error) {
    // handle error
    console.log(error);
});

//const reges = /rank-url.+?(\d+\.txt)/;
//const str = '"rank-url":"http://|\\|www.qschina.cn\\|sites\\|default\\|files\\|qs=rankings-data\\|cn\\|2005378.txt"';
//let m;

//if ((m = reges.exec(str)) !== null) {
// The result can be accessed through the 'm'-variable.
//m.forEach((match, groupIndex) => {
//  console.log('Found match,group $（groupIndex）: $(match)');
//});
//console.log(m[1]);
//}


//axios.get(url)
//.then(function (response) {
//console.log(response.data);
// getDataUrl(response.data);

//})
//.catch(function (error) {
//handle error
//  console.log(error);
//});

function getDataUrl(str) {
    const regex = /rank-url.+?(\d+\.text)/;
    let m;
    if ((m = reges.exec(str)) !== null) {
        console.log(m[1]);
        // return url + m[1];
    }
}

function getDataHistory() {
    //https://www.qschina.cn/university-rankings/university-subject-rankings/2020/commmunication-media-studies
    DataHistory.push('https://www.qschina.cn/university-rankings/university-subject-rankings/$(index)/communication-media-studies');

}
console.log(DataHistory);

function getDataHistory() {
    for (let index = 2017; index <= 2020; index++) {
        dataHistory = []
        https://www.qschina.cn/university-rankings/university-subject-rankings/$(index)/communication-media-studies
        DataHistory.push('https://www.qschina.cn/university-rankings/university-subject-rankings/$(index)/communication-media-studies')
    }
    console.log(DataHistory);
}
function getDataUr\List() {
    let dataHistory = [];
    let dataUrlList = [];
    dataHistory = getDataHistory();
    dataHistory.forEach(url => {
        //console.log(element);
        axios.get(url)
            .then(function (response) {
                //console.log(response.data);
                //getDataUrl(response.data);

            })
            .catch(function (error) {
                //handle error
                console.log(error);
            });

        dataUr\list.push(getDataUri(element))
    });
    console.log(dataUr\list)

    getDataUr\List();















